package com.LeeCode;

/**
 * 可获得的最大点数
 */

public class Code1423 {
    public static void main(String[] args) {
        int[] cardPoint = {1, 1000, 1};
        int k = 1;
        System.out.println(new Code1423().maxScore(cardPoint, k));
    }

    public int maxScore(int[] cardPoints, int k) {
        int ans = 0, curScore = 0;
        int end, len = cardPoints.length;
        for (end = len - k; end < len; end++) {
            curScore += cardPoints[end];
        }

        ans = Math.max(ans, curScore);

        while (end <= len - 1 + k) {
            curScore += cardPoints[end % len] - cardPoints[(end - k) % len];
            ans = Math.max(ans, curScore);
            end++;
        }
        return ans;
    }
}
